import sys
sys.path.append("/Research_Classroom/")

from gremlin_python import statics
from gremlin_python.process.anonymous_traversal import traversal
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.structure.graph import Graph
from gremlin_python.process.traversal import T
from gremlin_python.process.traversal import Order
from gremlin_python.process.traversal import Cardinality
from gremlin_python.process.traversal import Column
from gremlin_python.process.traversal import Direction
from gremlin_python.process.traversal import Operator
from gremlin_python.process.traversal import P
from gremlin_python.process.traversal import TextP
from gremlin_python.process.traversal import Pop
from gremlin_python.process.traversal import Scope
from gremlin_python.process.traversal import Barrier
from gremlin_python.process.traversal import Bindings
from gremlin_python.process.traversal import WithOptions
import GreNeoGraphQL.API.from_V as from_v
import GreNeoGraphQL.API.track_method_set as track
import GreNeoGraphQL.API.where_path_fliter as where

g = Graph().traversal().withRemote(DriverRemoteConnection('ws://211.71.15.48:8182/gremlin', 'g'))

#模拟from
a = from_v.from_text_contain(g,"with torch.no_grad():",property_name="code")
print(a)
#模拟 direct barrier
paths = track.track_run(g,a,"backward","cfg")

print(paths)


#模拟where
#error_path = where.path_code_not_contain_error(g,"asds",paths)#路径中包含某段代码即为错
error_path = where.path_code_contain_error(g,"eval",paths)#路径代码中不包含某段为本即为错
print(error_path)
#模拟select
for key in error_path:
    path = paths[key][0]
    key_lineno = g.V(key).lineo.toList()[0]
    print("第"+str(key_lineno)+"行代码,在路径"+str(path)+"上有错误，不应包含'asds'值")
